/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.center.web.action.integration;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sinodata.bsm.center.cache.ProbeCache;
import com.sinodata.bsm.center.cache.ResCache;
import com.sinodata.bsm.center.message.Messenger;
import com.sinodata.bsm.common.constants.IntegEventConstants;
import com.sinodata.bsm.common.message.ServiceMessage;
import com.sinodata.bsm.common.vo.Event;
import com.sinodata.bsm.common.vo.Probe;
import com.sinodata.bsm.common.vo.Res;

/**
 * <p>
 * Description: 
 * </p>
 * 
 * @author wangyazhou
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2013-6-26 上午10:39:49          wangyazhou        1.0         To create
 * </p>
 * 
 * @since    
 * @see     
 */

@Component
public class OpManagerEventDispatch implements IntegEventIf {

    private static final Logger logger = Logger.getLogger(OpManagerEventDispatch.class);

    @Autowired
    private ResCache resCache;

    @Autowired
    private ProbeCache probeCache;

    /* (non-Javadoc)
            * @see com.sinodata.bsm.center.web.action.integration.IntegEventIf#execute(java.lang.String)
            */
    @Override
    public void execute(Event event) {
        logger.info("[TIP]\t处理opmanaer中的事件");
        Long resId = event.getResId();
        Res res = resCache.get(resId);
        Probe probe = probeCache.get(res.getProbeId());

        if (probe == null || !"INMP".equals(probe.getType()) || !IntegEventConstants.SYSTEM_NAME_OP.equals(event.getRuleExpr())) {
            return;
        }

        ServiceMessage message = new ServiceMessage();
        message.setSrvId("SystemService");
        message.setMethod("clearEvent");
        message.setParams(new Object[] { event.getObjectId() });

        try {
            Messenger.getInstance().sendAsynMessage(res.getProbeId(), message);
        } catch (Exception e) {
            logger.error(e);
        }

    }
}
